import { createAppStore } from '@ac/store';
import type { StoreApi, UseBoundStore } from 'zustand';
import { createGlobalActions } from './actions';
import type { GlobalSlice } from './types';

export let useGlobalStore: UseBoundStore<StoreApi<GlobalSlice>>;

export const initGlobalStore = (props: any) => {
	if (props.useGlobalStore) {
		useGlobalStore = props.useGlobalStore;
	} else {
		useGlobalStore = createAppStore<GlobalSlice>((set, get, store) => ({
			language: 'zh-CN',
			...createGlobalActions(set, get, store)
		}));
	}
};
